using System;
using Gltf;
using UnityEngine;

internal class TextureUtility
{
    internal static Texture2D loadTextureAnyThreadPart(Model model, Gltf.Texture texture)
    {
        ImageCesium image = model.images[texture.source].cesium;
        TextureFormat pixelFormat = TextureFormat.Alpha8;
        switch (image.channels)
        {
            case 1:
                pixelFormat = TextureFormat.Alpha8;
                break;
            case 2:
                pixelFormat = TextureFormat.RG16;
                break;
            case 3:
            case 4:
            default:
                pixelFormat = TextureFormat.RGBA32;
                break;
        }
        Texture2D tex = new Texture2D(image.width, image.height, pixelFormat, true);
        tex.LoadRawTextureData(image.pixelData);
        return tex;
    }
}